package cn.wolfcode.wolf2w.web.controller;

import cn.wolfcode.wolf2w.annotation.RequireLogin;
import cn.wolfcode.wolf2w.annotation.UserParam;
import cn.wolfcode.wolf2w.cache.redis.service.IStrategyStatesVoService;
import cn.wolfcode.wolf2w.domain.Strategy;
import cn.wolfcode.wolf2w.domain.StrategyComment;
import cn.wolfcode.wolf2w.domain.UserInfo;
import cn.wolfcode.wolf2w.query.StrategyCommentQuery;
import cn.wolfcode.wolf2w.query.StrategyQuery;
import cn.wolfcode.wolf2w.service.IStrategyCommentService;
import cn.wolfcode.wolf2w.service.IStrategyService;
import cn.wolfcode.wolf2w.service.IStrategyThemeService;
import cn.wolfcode.wolf2w.uitl.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("strategies")
public class StrategyController {
    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private IStrategyThemeService strategyThemeService;
    @Autowired
    private IStrategyCommentService strategyCommentService;
    @Autowired
    private IStrategyStatesVoService strategyStatesVoService;
    @GetMapping("/detail")
    public Object detail(String id){
        //通过id查询对象
        Strategy strategy = strategyService.get(id);
        //约定好
        strategyStatesVoService.saveNum(id,1);
        return JsonResult.success(strategy);
    }

    @GetMapping("/query")
    public Object query(StrategyQuery qo){
        //通过目的的id查询所有对象
        return JsonResult.success(strategyService.query(qo));
    }
    @GetMapping("/themes")
    public Object themes(){
        //通过目的的id查询所有对象

        return JsonResult.success(strategyThemeService.lists());
    }
    //查询攻略评论
    @GetMapping("/comments")
    public Object comments(StrategyCommentQuery qo){
        //通过目的的id查询所有对象
        return JsonResult.success(strategyCommentService.query(qo));
    }
    //添加查询攻略评论\
    @RequireLogin //登陆才可以啦
    @PostMapping("/addComment")
    public Object addComment(StrategyComment strategyComment, @UserParam UserInfo userInfo){
        //添加一条
        strategyCommentService.addComment(strategyComment,userInfo);
        //添加成功的时候vo加一条评论
        strategyStatesVoService.voAddComment(strategyComment.getStrategyId(),1);
        return JsonResult.success();
    }
    //添加查询攻略评论\
    @RequireLogin //登陆才可以啦
    @PostMapping("/commentThumb")
    public Object commentThumb(String cid,String sid,@UserParam UserInfo userInfo){
        //添加一条
        strategyCommentService.commentThumb(cid,userInfo.getId());

        return JsonResult.success();
    }
    //点赞数,返回一个封装好的对象
    @GetMapping("/statisVo")
    public Object statisVo(String  sid){
        return JsonResult.success(strategyStatesVoService.getStrategyStatisVo(sid));
    }
    //收藏功能
    @RequireLogin
    @PostMapping("/favor")
    public Object favor(String  sid,@UserParam UserInfo userInfo){
        return JsonResult.success(strategyStatesVoService.favorClips(sid,userInfo.getId()));
    }
    //收藏功能
    @RequireLogin
    @PostMapping("/strategyThumbup")
    public Object strategyThumbup(String  sid,@UserParam UserInfo userInfo){
        return JsonResult.success(strategyStatesVoService.strategyThumbup(sid,userInfo.getId()));
    }
}
